#include "collider-box.h"
#include "../geometry/intersect3d.h"
#include "../scene/node.h"
#include "../log.h"

ColliderBox::ColliderBox(Node *node) : ColliderBase(node)
{
    Log::print("创建物理Box类...." + node->getID() + "   " + std::to_string(reinterpret_cast<uintptr_t>(this)));
    // Log::print((this->getID()) + "      "+ "this创建box="  +  std::to_string(reinterpret_cast<uintptr_t>(this)));
    this->setGeometry(PhysicsColliderGeometry::Box);
}

float ColliderBox::colliderTest(ColliderBase *collider)
{
    Log::print("ColliderBox的碰撞0....." + std::to_string(collider->getGeometry()));
    if (!((this->getGroup() & collider->getMask()) && (this->getMask() & collider->getGroup())))
    {
        return -1;
    }
    Log::print("ColliderBox的碰撞1....." + std::to_string(collider->getGeometry()));
    if (collider->getGeometry() == PhysicsColliderGeometry::Box)
    {
        // box 和 box检测碰撞

        bool isAABBOK = Intersect3D::aabbWithAABB(this->getAABB(), collider->getAABB());
        Log::print("ColliderBox的碰撞2....." + std::string(isAABBOK ? "true" : "false"));
        if (isAABBOK)
        { // aabb 检测OK
            return 1;
        }
    }
    return -1;
}

ColliderBox::~ColliderBox()
{
}
